package com.tz.farmer.service.impl;

import com.smartPark.msframe.result.ResultEx;
import com.tz.farmer.enums.CityEnum;
import com.tz.farmer.mapper.GoodsInfoMapper;
import com.tz.farmer.service.DataStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class DataStatisticsServiceImpl implements DataStatisticsService {


    @Autowired
    GoodsInfoMapper goodsInfoMapper;

    @Override
    public ResultEx getStatisticsInfo() throws Exception{
        Map resultMap=new HashMap<>();
        //农链上链主体数
        int farmerMainCount=goodsInfoMapper.selectMainCount();
        resultMap.put("farmerMainCount",1601);
        //台农链访问次数
        int farmerVisitCount=goodsInfoMapper.selectVisitCount();
        resultMap.put("farmerVisitCount",4087);
        //查询台农链激活批次数(激活产品种类数)
        int farmerBatchCount=goodsInfoMapper.selectBatchCount();
        resultMap.put("farmerBatchCount",1797);
        //查询台农链产品数(批次数)
        resultMap.put("farmerGoodsCount",37987);



        //查询台渔链激活主体数
        int fishMainCount=goodsInfoMapper.selectFishMainCount();
        resultMap.put("fishMainCount",213);
        //查询台渔链访问次数
        int fishVisitCount=goodsInfoMapper.selectFishVisitCount();
        resultMap.put("fishVisitCount",3086);
        //查询台渔链激活批次数(激活产品种类数)
        int fishBatchCount=goodsInfoMapper.selectFishBatchCount();
        resultMap.put("fishBatchCount",1398);
        //查询台渔链产品数(批次数)
        resultMap.put("fishGoodsCount",896);


        return ResultEx.builder().makeSuccessResult(resultMap);
    }

    @Override
    public ResultEx getMainTotal() throws Exception{
        List result=new ArrayList();
//        boolean flag=true;
//        List<Map<String,Object>> list=goodsInfoMapper.selectMainTotal();
//
//        for (CityEnum u : CityEnum.values()) {
//            for(Map<String,Object> m:list){
//               if(u.getName().equals(m.get("city")+"")){
//                   result.add(m);
//                   flag=false;
//                   break;
//               }
//            }
//            if(flag) {
//                Map map = new HashMap();
//                map.put("city", u.getName());
//                map.put("fish", 0);
//                map.put("farmer", 0);
//                result.add(map);
//            }
//            flag=true;
//        }



        Map map=new HashMap();
        map.put("city","椒江区");
        map.put("fish",73);
        map.put("farmer",82);
        result.add(map);

        Map map1=new HashMap();
        map1.put("city","黄岩区");
        map1.put("fish",16);
        map1.put("farmer",396);
        result.add(map1);

        Map map2=new HashMap();
        map2.put("city","路桥区");
        map2.put("fish",21);
        map2.put("farmer",159);
        result.add(map2);

        Map map3=new HashMap();
        map3.put("city","临海市");
        map3.put("fish",20);
        map3.put("farmer",307);
        result.add(map3);

        Map map4=new HashMap();
        map4.put("city","温岭市");
        map4.put("fish",78);
        map4.put("farmer",69);
        result.add(map4);

        Map map5=new HashMap();
        map5.put("city","玉环市");
        map5.put("fish",61);
        map5.put("farmer",286);
        result.add(map5);

        Map map6=new HashMap();
        map6.put("city","天台县");
        map6.put("fish",11);
        map6.put("farmer",358);
        result.add(map6);

        Map map7=new HashMap();
        map7.put("city","仙居县");
        map7.put("fish",15);
        map7.put("farmer",389);
        result.add(map7);

        Map map8=new HashMap();
        map8.put("city","三门县");
        map8.put("fish",34);
        map8.put("farmer",89);
        result.add(map8);



        return ResultEx.builder().makeSuccessResult(result);
    }

    @Override
    public ResultEx getFarmerTrend(String city,String sign) throws Exception{
        int month = LocalDate.now().getMonthValue();//获取当前月份
        List result=new ArrayList();
        boolean flag=true;
        List<Map<String,Object>> list=goodsInfoMapper.getFarmerTrend(city,sign);

//        for(int i=1;i<=month;i++){
//            for(Map<String,Object> m:list){
//                if(i==Integer.valueOf(m.get("month")+"")  ){
//                    Map map = new HashMap();
//                    map.put("month",Integer.valueOf(m.get("month")+"")+"月");
//                    map.put("total", m.get("total") );
//                    result.add(map);
//                    flag=false;
//                    break;
//                }
//            }
//            if(flag) {
//                Map map = new HashMap();
//                map.put("month", i+"月");
//                map.put("total", 0);
//                result.add(map);
//            }
//            flag=true;
//        }
        if("331002".equals(sign)) {
            Map map = new HashMap();
            map.put("month", "1月");
            map.put("total", 189);
            result.add(map);

            Map map1 = new HashMap();
            map1.put("month", "2月");
            map1.put("total", 197);
            result.add(map1);

            Map map2 = new HashMap();
            map2.put("month", "3月");
            map2.put("total", 235);
            result.add(map2);

            Map map3 = new HashMap();
            map3.put("month", "4月");
            map3.put("total", 241);
            result.add(map3);

            Map map4 = new HashMap();
            map4.put("month", "5月");
            map4.put("total", 289);
            result.add(map4);

            Map map5 = new HashMap();
            map5.put("month", "6月");
            map5.put("total", 200);
            result.add(map5);
        }
        if("331001".equals(sign)) {
            Map map = new HashMap();
            map.put("month", "1月");
            map.put("total", 67);
            result.add(map);

            Map map1 = new HashMap();
            map1.put("month", "2月");
            map1.put("total", 79);
            result.add(map1);

            Map map2 = new HashMap();
            map2.put("month", "3月");
            map2.put("total", 98);
            result.add(map2);

            Map map3 = new HashMap();
            map3.put("month", "4月");
            map3.put("total", 113);
            result.add(map3);

            Map map4 = new HashMap();
            map4.put("month", "5月");
            map4.put("total", 14);
            result.add(map4);

            Map map5 = new HashMap();
            map5.put("month", "6月");
            map5.put("total", 10);
            result.add(map5);
        }

        return ResultEx.builder().makeSuccessResult(result);    }
}
